<!-- 在这个文件对每个tab对应的列表进行渲染 -->
<template>
	<view class="paryorder-content">
		<!-- 这里设置了z-paging加载时禁止自动调用reload方法，自行控制何时reload（懒加载）-->
		<!--  :enable-back-to-top="currentIndex===tabIndex" 在微信小程序上可以多加这一句，因为默认是允许点击返回顶部的，但是这个页面有多个scroll-view，会全部返回顶部，所以需要控制是当前index才允许点击返回顶部 -->
		<z-paging ref="paging" v-model="dataList" @query="queryList" :fixed="false" :auto="false">
			<!-- 如果希望其他view跟着页面滚动，可以放在z-paging标签内 -->
			<view class="payorder-container" v-for="(item,index) in dataList" :key="index" >
				<view class="payorder-header">
					<text style="font-size: 26rpx;font-weight: bold; color: #333;">{{
						$fui.dateFormatter(item.applicantTime,'y-m-d h:i')
					 }}</text>
					<view class="u-flex">
						<text style="font-size: 26rpx;font-weight: bold; color: #FF551A;margin-left: 10rpx;">{{item.status!==-1?paymentStatus[item.status]:"已作废"}}</text>
					</view>
				</view>
				<view class="payorder-section">
					<view class="section-list">
						<view class="u-flex" style="margin-bottom: 16rpx;">
							<text style="font-size: 24rpx; color: #999;">采购商</text>
							<view  class="u-m-l-20">{{item.buyerName||'空'}}</view>
						</view>
						<view class="u-flex">
							<text style="font-size: 24rpx; color: #999;">报价单</text>
							<view class="u-m-l-20">{{item.priceTemplateName}}</view>
						</view>
					</view>
					
				</view>
				<view class="footer u-flex u-row-right">
					<view class="look-price" @click="itemClick(item)">查看</view>
				</view>
			</view>
			
		</z-paging>
		
	</view>
</template>

<script>
	import {useShopStore} from '@/store/shop.js';
	import { mapState } from 'pinia';
	export default {
		data() {
			return {
				//v-model绑定的这个变量不要在分页请求结束中自己赋值！！！
				dataList: [],
				firstLoaded: false,
				paymentStatus:['待审核','生效中','已拒绝','已过期','草稿','保存']
			}
		},
		props:{
			//当前组件的index，也就是当前组件是swiper中的第几个
			tabIndex: {
				type: Number,
				default: function(){
					return 0
				}
			},
			//当前swiper切换到第几个index
			currentIndex: {
				type: Number,
				default: function(){
					return 0
				}
			},
			value:{
				type: Number,
				default: function(){
					return 0
				}
			},
			keyWords:{
				type: String,
				default: function(){
					return ''
				}
			}
		},
		watch: {
			currentIndex: {
				handler(newVal) {
					if(newVal === this.tabIndex){
						//懒加载，当滑动到当前的item时，才去加载
						if(!this.firstLoaded){
							setTimeout(() => {
								this.$refs.paging.reload();
							}, 100);
						}
					}
				},
				immediate: true
			},
			keyWords:{
				handler(newVal) {
					//懒加载，当滑动到当前的item时，才去加载
					setTimeout(() => {
						console.log(newVal);
						this.$refs.paging.reload();
					}, 100);
				},
			}
		},
	computed: {
		...mapState(useShopStore, {
		  storeShop: 'shop'}),
	},
		methods: {
			async queryList(pageNo, pageSize) {
				//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//模拟请求服务器获取分页数据，请替换成自己的网络请求
				const params = {
					pageIndex: pageNo,
					pageSize: pageSize,
					shopId:this.storeShop.id,
					status:this.value
				}
				if(this.keyWords!==''){
					params.keywords = this.keyWords;
				}
				uni.showLoading({
					title: 'loading...',
					mask: false
				});
				const res = await this.$newHttp.get('api/v1.2/Shop/SalesGetSigningHistory', { params: params } );
				uni.hideLoading({
					title: 'loading...'
				})
				if(res.code === 200){
					this.$refs.paging.complete(res.data.list);
					this.firstLoaded = true;
					
				}else{
					this.$refs.paging.complete(false);
				}
			},
			itemClick(item) {
				if(item.paymentStatus != 5){
					this.$mRouter.push({
						route: '/pages/sale/myCustomers/signDetails?data='+JSON.stringify(item),
					})
				}else{
					this.$u.toast('该付款单已关闭')
				}
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* 注意:父节点需要固定高度，z-paging的height:100%才会生效 */
	.paryorder-content {
		height: 100%;
		
	}
	.payorder-container{
		background-color: #fff;
		box-sizing: border-box;
		padding: 30rpx 30rpx 20rpx;
		margin-bottom: 20rpx;
		.payorder-header{
			display: flex;
			justify-content: space-between;
		}
		.payorder-section{
			display: flex;
			box-sizing: border-box;
			padding: 30rpx 0;
			border-bottom: solid 1px #eaeaea;
			margin: 0rpx 0 20rpx;
			.section-image{
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
			}
			.section-list{
				flex: 1;
				margin-left: 20rpx;
			}
			
		}
		.look-price{
			width: 160rpx;
			height: 70rpx;
			border: 1px solid #ffbb1a;
			color: #ffbb1a;
			text-align: center;
			line-height: 70rpx;
			border-radius: 35rpx;
		}
	}


</style>
